package test2.算法.斐波那契数列;

public class App {

	public static void main(String[] args) {
		System.out.println(fei2(6));
	}
	
	/**
	 * 0 1 1 2 3 5 8...
	 * 0 1 2 3 4 5 6
	 */
	
	public static int fei1(int i) {
		if(i==0||i==1) {
			return i;
		} else {
			return fei1(i-1) + fei1(i-2);
		}
	}
	
	public static int fei2(int i) {
		int curr = 0,prev = 0;
		for(int j=0;j<=i;j++) {
			if(j==0||j==1) {
				curr = j;
			} else {
				int temp = curr;
				curr = curr + prev;
				prev = temp;
			}
			System.out.println("curr="+curr+",prev="+prev);
		}
		return curr;
	}
	
}
